//index.js
//获取应用实例
const app = getApp()
const WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.imgurl,
    logo: false,
    content:false,
    videotype:false
  },
  end:function(e){
    console.log(e)
    let that = this;
    if (!e.detail.fullScreen){
      var Video = wx.createVideoContext('video')
      that.setData({ videotype: false })
      console.log('进入全屏')
    }else{
      console.log('推书全屏')
    }
    
  },
  play:function(){
    var Video = wx.createVideoContext('video')
    console.log('-----')
    let that = this;
    that.setData({ videotype:true})
    Video.requestFullScreen()
    Video.play()
    
  },
  show:function(){
    this.setData({ content: !this.data.content})
  },
  navTo:function(e){
    app.navTo(e.currentTarget.dataset.url)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    app.request({
      url: 'index/program/HomeRole',
      method: 'post',
      type: 0,
      success: function (res) {
        console.log(res.data.content)
        WxParse.wxParse('article', 'html', res.data.content, that, 5)
      }
    })
    app.request({   
      url: 'index/program/banner',
      method: 'post',
      type: 0,
      success: function (res) {
        that.setData({banner:res.data})
      }
    })
  },
  searchtxt:function(e){
    this.setData({ searchtxt: e.detail.value})
  },
  search:function(){
    let that = this;
    app.request({
      url: 'index/program/SearchData',
      method: 'post',
      type: 0,
      data: {
        key: that.data.searchtxt
      },
      success: function (res) {
        console.log(res)
        if(res.data != ''){
          app.navTo('/pages/list/index?type=3')
          wx.setStorageSync('searchdata',res.data)
        }else{
          wx.showToast({
            title: '暂无数据',
            icon:'none'
          })
        }
        return false;
        that.setData({
          data: res.data,
          pid: options.pid,
          bid: options.bid
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    wx.getStorage({
      key: 'userid',
      success(res) {
      },
      fail(err){
        that.setData({logo:true})
      }
    })
  },
  
  //登录
  sendRequest: function (res) {
    let that = this;
    if (!res.detail.rawData) {
      wx.showModal({
        title: '提示',
        content: '请重新点击授权',
      })
      wx.hideLoding()
      return false;
    }
    wx.showLoading({
      title: '请稍后',
    })
    console.log(res)
    wx.login({
      success: function (code) {
        app.request({
          url: 'index/program/TowLogin',
          method:'post',
          type:0,
          data:{
            code: code.code,
            iv: res.detail.iv,
            encryptedData: res.detail.encryptedData
          },
          success:function(res){
            wx.hideLoading();
            that.setData({logo:false})
            wx.setStorageSync('userid', res.data)
          },

        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})
